package com.example.springboot.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.springboot.common.Result;
import com.example.springboot.entity.*;
import com.example.springboot.mapper.McDustMapper;
import com.example.springboot.service.DustService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@CrossOrigin
@RequestMapping("/selectDust")
public class DustController {
    @Autowired
    DustService DustService ;

    @Autowired
    McDustMapper mcDustMapper;

    //查找所有煤尘的数据
    // 查找所有媒尘的数据
    @RequestMapping("/selectAllMc")
    public Result selectAllMc(
            @RequestParam(defaultValue = "1") int pageNum,
            @RequestParam(defaultValue = "15") int pageSize) {
        PageInfo<McDust> result = DustService.selectAllMc(pageNum, pageSize);
        System.out.println("Returning data for /selectAllMc: " + result.getList());
        return Result.success(result);
    }

    // 查询所有水泥数据
    @RequestMapping("/selectAllSn")
    public Result selectAllSn(
            @RequestParam(defaultValue = "1") int pageNum,
            @RequestParam(defaultValue = "15") int pageSize) {
        PageInfo<McDust> result = DustService.selectAllSn(pageNum, pageSize);
        System.out.println("Returning data for /selectAllSn: " + result.getList());
        return Result.success(result);
    }

    // 查询所有矽尘数据
    @RequestMapping("/selectAllXc")
    public Result selectAllXc(
            @RequestParam(defaultValue = "1") int pageNum,
            @RequestParam(defaultValue = "15") int pageSize) {
        PageInfo<McDust> result = DustService.selectAllXc(pageNum, pageSize);
        System.out.println("Returning data for /selectAllXc: " + result.getList());
        return Result.success(result);
    }

    // 查询所有粉尘数据
    @RequestMapping("/selectAllDust")
    public Result selectAllDust(
            @RequestParam(defaultValue = "1") int pageNum,
            @RequestParam(defaultValue = "15") int pageSize) {
        PageInfo<McDust> result = DustService.selectAllDust(pageNum, pageSize);
        System.out.println("Returning data for /selectAllDust: " + result.getList());
        return Result.success(result);
    }

    //    按地点查询媒尘数据
    @RequestMapping("/selectMcByPlace")
    public Result selectMcByPlace(@RequestParam(defaultValue = "1") int pageNum,
                                  @RequestParam(defaultValue = "15") int pageSize,
                                  String place) {
        PageInfo<McDust> result = DustService.selectMcByPlace(pageNum, pageSize, place);
        System.out.println("Returning data for /selectMcByPlace: " + result.getList());

        if (result.getList() == null || result.getList().isEmpty()) {
            return Result.error("该城市没有媒尘数据");
        }

        return Result.success(result);
    }

    //    按地点查询水泥数据
    @RequestMapping("/selectSnByPlace")
    public Result selectSnByPlace(@RequestParam(defaultValue = "1") int pageNum,
                                  @RequestParam(defaultValue = "15") int pageSize,
                                  String place) {
        PageInfo<McDust> result = DustService.selectSnByPlace(pageNum, pageSize, place);
        System.out.println("Returning data for /selectSnByPlace: " + result.getList());

        if (result.getList() == null || result.getList().isEmpty()) {
            return Result.error("该城市没有水泥数据");
        }
        return Result.success(result);
    }

    //    按地点查询矽尘数据
    @RequestMapping("/selectXcByPlace")
    public Result selectXcByPlace(@RequestParam(defaultValue = "1") int pageNum,
                                  @RequestParam(defaultValue = "15") int pageSize,
                                  String place) {
        PageInfo<McDust> result = DustService.selectXcByPlace(pageNum, pageSize, place);
        System.out.println("Returning data for /selectXcByPlace: " + result.getList());

        if (result.getList() == null || result.getList().isEmpty()) {
            return Result.error("该城市没有矽尘数据");
        }
        return Result.success(result);
    }

    //    查询某一年的媒尘数据
    @RequestMapping("/selectMcDustByYear")
    public Result selectMcDustByYear(
            @RequestParam(defaultValue = "1") int pageNum,
            @RequestParam(defaultValue = "15") int pageSize,
            int year) {

        PageInfo<McDust> result = DustService.selectMcDustByYear(pageNum, pageSize, year);
        System.out.println("Returning data for /selectMcDustByYear: " + result.getList());
        if (result.getList() == null || result.getList().isEmpty()) {
            return Result.error("未查到数据");
        }
        return Result.success(result);
    }

    //    查询某一年的水泥数据
    @RequestMapping("/selectSnDustByYear")
    public Result selectSnDustByYear(
            @RequestParam(defaultValue = "1") int pageNum,
            @RequestParam(defaultValue = "15") int pageSize,
            int year) {
        PageInfo<McDust> result = DustService.selectSnDustByYear(pageNum, pageSize, year);
        System.out.println("Returning data for /selectSnDustByYear: " + result.getList());
        if (result.getList() == null || result.getList().isEmpty()) {
            return Result.error("未查到数据");
        }
        return Result.success(result);
    }

    //    查询某一年的矽尘数据
    @RequestMapping("/selectXcDustByYear")
    public Result selectXcDustByYear(
            @RequestParam(defaultValue = "1") int pageNum,
            @RequestParam(defaultValue = "15") int pageSize,
            int year) {
        PageInfo<McDust> result = DustService.selectXcDustByYear(pageNum, pageSize, year);
        System.out.println("Returning data for /selectXcDustByYear: " + result.getList());
        if (result.getList() == null || result.getList().isEmpty()) {
            return Result.error("未查到数据");
        }
        return Result.success(result);
    }



    //    按照地点查询媒尘某年的数据
    @RequestMapping("/selectMcCityByYear")
    public Result selectMcCityByYear(@RequestParam(defaultValue = "1") int pageNum,
                                     @RequestParam(defaultValue = "15") int pageSize,
                                     String place,int year) {
        PageInfo<McDust> result = DustService.selectMcByYear(pageNum, pageSize, year, place);
        System.out.println("Returning data for /selectMcCityByYear: " + result.getList());

        if (result.getList() == null || result.getList().isEmpty()) {
            return Result.error("没有数据");
        }
        return Result.success(result);
    }

    //    按照地点查询水泥某年的数据
    @RequestMapping("/selectSnCityByYear")
    public Result selectSnCityByYear(@RequestParam(defaultValue = "1") int pageNum,
                                     @RequestParam(defaultValue = "15") int pageSize,
                                     String place,int year) {
        PageInfo<McDust> result = DustService.selectSnByYear(pageNum, pageSize, year, place);
        System.out.println("Returning data for /selectSnCityByYear: " + result.getList());

        if (result.getList() == null || result.getList().isEmpty()) {
            return Result.error("没有数据");
        }
        return Result.success(result);
    }

    //    按照地点查询水泥某年的数据
    @RequestMapping("/selectXcCityByYear")
    public Result selectXcCityByYear(@RequestParam(defaultValue = "1") int pageNum,
                                     @RequestParam(defaultValue = "15") int pageSize,
                                     String place,int year) {
        PageInfo<McDust> result = DustService.selectXcByYear(pageNum, pageSize, year, place);
        System.out.println("Returning data for /selectSnCityByYear: " + result.getList());

        if (result.getList() == null || result.getList().isEmpty()) {
            return Result.error("没有数据");
        }
        return Result.success(result);
    }

    //    查询华昊体检数据
    @RequestMapping("/selectHh")
    public Result selectHh(
            @RequestParam(defaultValue = "1") int pageNum,
            @RequestParam(defaultValue = "15") int pageSize) {
        PageInfo<PhysicalExamination> result = DustService.selectAllHh(pageNum, pageSize);
        System.out.println("Returning data for /selectHh: " + result.getList());

        if (result.getList() == null || result.getList().isEmpty()) {
            return Result.error("没有数据");
        }
        return Result.success(result);
    }


    //    查询大众体检数据
    @RequestMapping("/selectDz")
    public Result selectDz(
            @RequestParam(defaultValue = "1") int pageNum,
            @RequestParam(defaultValue = "15") int pageSize) {
        PageInfo<PhysicalNxdz> result = DustService.selectAllDz(pageNum, pageSize);
        System.out.println("Returning data for /selectDz: " + result.getList());

        if (result.getList() == null || result.getList().isEmpty()) {
            return Result.error("没有数据");
        }
        return Result.success(result);
    }

    //    查询青龙体检数据
    @RequestMapping("/selectQingLong")
    public Result selectQingLong(
            @RequestParam(defaultValue = "1") int pageNum,
            @RequestParam(defaultValue = "15") int pageSize) {
        PageInfo<PhysicalQinglong> result = DustService.selectAllQingLong(pageNum, pageSize);
        System.out.println("Returning data for /selectQingLong: " + result.getList());

        if (result.getList() == null || result.getList().isEmpty()) {
            return Result.error("没有数据");
        }
        return Result.success(result);
    }


    //    查询银川栏劫体检数据
    @RequestMapping("/selectYinchuan")
    public Result selectYinchuan(
            @RequestParam(defaultValue = "1") int pageNum,
            @RequestParam(defaultValue = "15") int pageSize) {
        PageInfo<PhysicalYclanjie> result = DustService.selectAllYinchuan(pageNum, pageSize);
        System.out.println("Returning data for /selectYinchuan: " + result.getList());

        if (result.getList() == null || result.getList().isEmpty()) {
            return Result.error("没有数据");
        }
        return Result.success(result);
    }


    //    查询一品生物体检数据
    @RequestMapping("/selectYpsw")
    public Result selectYpsw(
            @RequestParam(defaultValue = "1") int pageNum,
            @RequestParam(defaultValue = "15") int pageSize) {
        PageInfo<PhysicalYiping> result = DustService.selectAllYpsw(pageNum, pageSize);
        System.out.println("Returning data for /selectYpsw: " + result.getList());

        if (result.getList() == null || result.getList().isEmpty()) {
            return Result.error("没有数据");
        }
        return Result.success(result);
    }

    //   模糊查询所有数据
//    再试试
//    @GetMapping("/search")
//    public Page<McDust> searchDust(
//            @RequestParam(defaultValue = "1") int pageNum,
//            @RequestParam(defaultValue = "10") int pageSize,
//            @RequestParam Map<String, Object> conditions) {
//
//        // 移除分页参数
//        conditions.remove("pageNum");
//        conditions.remove("pageSize");
//
//        // 调用服务层方法
//        Page<McDust> result = DustService.selectAllDustWithConditions(pageNum, pageSize, conditions);
//
//        // 返回 Page 对象
//        return result;
//    }
}
